package LawsonTransformJava.pgm;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.TreeMap;

public class PRHistReport extends Report {
	
	protected TreeMap<String, Integer> recCounts = new TreeMap<String, Integer>();
	
	public PRHistReport(File fOutput, Date runStart) throws IOException {
		super(fOutput, runStart);
	}
	
	public void initCounter(String name, int value) {
		if (recCounts.containsKey(name)) {
			recCounts.remove(name);
		}
		recCounts.put(name, value);
	}

	public void addToCounter(String name, int value) {
		Integer oldValue = null;
		int newVInt = value;
		if (recCounts.containsKey(name)) {
			oldValue = recCounts.get(name);
			newVInt = oldValue.intValue() + value;
		}
		recCounts.put(name, Integer.valueOf(newVInt));
	}
	
	public void writeRecordCounts() throws IOException {
		String key = null;
		write(writeRptHeading() + "\n");
		write("\n\n\n\n\n");
		//Cycle through record counts
		Iterator iter = recCounts.keySet().iterator();
		while(iter.hasNext()){
			key = ((String)iter.next()).toString();
			write(key + ": ");
			write(((Integer)recCounts.get(key)).intValue() + "\n");
		}
		write("\n\n\n\n\n\n\n\n\n");
		//Write timestamp to output file
		write(fOutput.getName() + " Start    " + runStart + "\n");
		//Write timestamp to output file
		write(fOutput.getName() + " Complete " + df.format(new Date()) + "\n");
		write(writeRptFooter());
	}
}
